﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Pakxel.Data;
using Telerik.WinControls.UI;
using System.Data.Common;
using System.Collections.ObjectModel;
using Telerik.WinControls.Data;
using Telerik.WinControls.UI.Export;

namespace Pakxel.SmartLogistic.Reportes
{
    public partial class CartasPorte : Telerik.WinControls.UI.RadForm
    {
        private MEDataDataContext DataContext;
        public CartasPorte()
        {
            InitializeComponent();
            DataContext = new Data.MEDataDataContext(WorkBench.ConnectionString);
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            if (RVCP.ReportSource == null)
                RVCP.ReportSource = new RptCartasPorte();

            IEnumerable<T017> Facs = (from F in DataContext.T017s where F.T017Fecha >= Desde.Value && F.T017Fecha <= Hasta.Value select F).ToList();
            int[] CPs = (from C in Facs select C.T021NoCartaPorte).ToArray();

            ((RptCartasPorte)RVCP.ReportSource).Database.Tables["Pakxel_Data_T021"].SetDataSource(
                (from D in DataContext.T021s
                 where CPs.Contains(D.T021NoCartaPorte) 
                 select
                     new { T021NoCartaPorte = D.T021NoCartaPorte,
                         T005NoViaje = D.T005NoViaje,
                         T021NoCartaPorteCte = D.T021NoCartaPorteCte,
                         T021Flete = D.T021Flete,
                         T021FleteME = D.T021FleteME,
                         T021Subtotal = D.T021Subtotal,
                         T021Iva = D.T021Iva,
                         T021Retencion = D.T021Retencion,
                         T021Total = D.T021Total,
                         T021Fecha = D.T021Fecha,
                         T021Pedimento = D.T021Pedimento ?? string.Empty,
                         T021Fianza = D.T021Fianza,
                         T021Facturada = D.T021Facturada
                     })
                );

            ((RptCartasPorte)RVCP.ReportSource).Database.Tables["Pakxel_Data_T017"].SetDataSource(Facs);

            RVCP.RefreshReport();
        }

        private void Hasta_ValueChanged(object sender, EventArgs e)
        {
            Desde.MaxDate = Hasta.Value;
        }

        private void Desde_ValueChanged(object sender, EventArgs e)
        {
            Hasta.MinDate = Desde.Value;
        }

        private void CartasPorte_Load(object sender, EventArgs e)
        {
        }
    }
}
